package com.tancire.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tancire.common.annotation.Log;
import com.tancire.common.core.controller.BaseController;
import com.tancire.common.core.domain.AjaxResult;
import com.tancire.common.enums.BusinessType;
import com.tancire.system.domain.AppModule;
import com.tancire.system.service.IAppModuleService;
import com.tancire.common.utils.poi.ExcelUtil;
import com.tancire.common.core.page.TableDataInfo;

/**
 * APP页面配置Controller
 *
 * @author chenchao
 * @date 2024-01-15
 */
@RestController
@RequestMapping("/system/appModule")
public class AppModuleController extends BaseController {
    @Resource
    private IAppModuleService appModuleService;

    /**
     * 查询APP页面配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppModule appModule) {
        startPage();
        List<AppModule> list = appModuleService.selectAppModuleList(appModule);
        return getDataTable(list);
    }

    /**
     * 导出APP页面配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:export')")
    @Log(title = "APP页面配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AppModule appModule) {
        List<AppModule> list = appModuleService.selectAppModuleList(appModule);
        ExcelUtil<AppModule> util = new ExcelUtil<AppModule>(AppModule.class);
        util.exportExcel(response, list, "APP页面配置数据");
    }

    /**
     * 获取APP页面配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(appModuleService.selectAppModuleById(id));
    }

    /**
     * 新增APP页面配置
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:add')")
    @Log(title = "APP页面配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppModule appModule) {
        return toAjax(appModuleService.insertAppModule(appModule));
    }

    /**
     * 修改APP页面配置
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:edit')")
    @Log(title = "APP页面配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppModule appModule) {
        return toAjax(appModuleService.updateAppModule(appModule));
    }

    /**
     * 删除APP页面配置
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:remove')")
    @Log(title = "APP页面配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(appModuleService.deleteAppModuleByIds(ids));
    }

    /**
     * 查询APP页面配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:appModule:refresh')")
    @GetMapping("/refresh/redis")
    public AjaxResult refreshRedis() {
        this.appModuleService.refreshRedis();
        return AjaxResult.success();
    }
}
